package nl.hanze.designpatterns.res.builder;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

import nl.hanze.designpatterns.domain.Answer;
import nl.hanze.designpatterns.domain.FAQcomponent;
import nl.hanze.designpatterns.domain.Question;
public class Builder{
	
	private int counter=0;
	public void Build(){
			ArrayList<FAQcomponent> list = new ArrayList<FAQcomponent>();
						
			Question q1 = new Question("Staat de printer aan?",getUniqueID(), "De printer doet het niet");
			list.add(q1);
			
			Answer answer = new Answer("ja",getUniqueID());
			q1.addAnswer(answer);
			list.add(answer);
			Question q2 = new Question("Heeft u de printer driver geinstalleerd?",getUniqueID());
			list.add(q2);
	answer.setQuestion(q2);
			Answer answer4 = new Answer("ja, Ga naar de administrator!",getUniqueID());
			list.add(answer4);
			q2.addAnswer(answer4);
			Answer answer5 = new Answer("nee, installer de juiste printer driver!",getUniqueID());
			q2.addAnswer(answer5);
			list.add(answer5);
	
			Question q4 = new Question("probleem opgelost?",getUniqueID());
			answer5.setQuestion(q4);
			list.add(q4);
	answer5.setQuestion(q4);
			Answer answer6 = new Answer("ja",getUniqueID());
			q4.addAnswer(answer6);
			list.add(answer6);
			Answer answer7 = new Answer("nee, ga naar de administrator!",getUniqueID());
			q4.addAnswer(answer7);
			list.add(answer7);
			Answer answer1 = new Answer("nee, Doe de printer aan!",getUniqueID());
			list.add(answer1);
			q1.addAnswer(answer1);
		
			Question q3 = new Question("Is het probleem opgelost?",getUniqueID());
			list.add(q3);
	answer1.setQuestion(q3);
			Answer answer2 = new Answer("ja",getUniqueID());
			q3.addAnswer(answer2);
			list.add(answer2);
			Answer answer3 = new Answer("nee",getUniqueID());
			q3.addAnswer(answer3);
			list.add(answer3);
	
	answer3.setQuestion(q2);	
				try
			      {
			         FileOutputStream fileOut =
			         new FileOutputStream("tree.ser");
			         ObjectOutputStream out = new ObjectOutputStream(fileOut);
			         
			         for(int i = 0; i < list.size(); i++)
			         out.writeObject(list.get(i));
			         
			         out.close();
			         fileOut.close();
			         System.out.printf("Serialized data is saved");
			      }catch(IOException i)
			      {
			          i.printStackTrace();
			      }
	}
	
	public int getUniqueID(){
		counter++;
		return counter;
	}
	
	public static void main(String args[]){
		Builder builder = new Builder();
		builder.Build();
	}
		
		
}
